﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;

// test only
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.BLL
{
    public class B_ICM_Bidder : IBLL_ICM_Bidder
    {
        Common common = new Common();
        private static readonly IDAL_ICM_Bidder dal = DataAccess.Create_ICM_Bidder();

        public B_ICM_Bidder()
        {

        }

        public IList<M_ICM_Bidder> GetFull(string icm_bid_seq, string icm_pr_seq
            , string collateral_return_status, string receive_status, string offer_status, string winner_status)
        {
            Nullable<int> nicm_bid_seq = common.ConvertNullInt(icm_bid_seq);
            Nullable<int> nicm_pr_seq = common.ConvertNullInt(icm_pr_seq);
            return dal.GetFull(nicm_bid_seq, nicm_pr_seq
                , collateral_return_status, receive_status, offer_status, winner_status);
        }

        public IList<M_ICM_Bidder> GetList(string icm_bid_seq, string icm_pr_seq
            , string collateral_return_status, string receive_status, string offer_status, string winner_status)
        {
            Nullable<int> nicm_bid_seq = common.ConvertNullInt(icm_bid_seq);
            Nullable<int> nicm_pr_seq = common.ConvertNullInt(icm_pr_seq);
            return dal.GetList(nicm_bid_seq, nicm_pr_seq
                , collateral_return_status, receive_status, offer_status, winner_status);
        }

        public M_ICM_Bidder GetInfo(string seq)
        {
            int nSeq;
 
            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public M_ICM_Bidder GetInfo(string icm_bid_seq, string contact_seq)
        {
            Nullable<int> nicm_bid_seq = common.ConvertNullInt(icm_bid_seq);
            Nullable<int> ncontact_seq = common.ConvertNullInt(contact_seq);
            return dal.GetInfo(nicm_bid_seq, ncontact_seq);
        }

        //public string SelectRecentInsertedRoleSeq()
        //{
        //    return dal.SelectRecentInsertedRoleSeq();
        //}

        public string Insert(M_ICM_Bidder info)
        {
            try
            {
                return dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void UpdateReceive(M_ICM_Bidder info)
        {
            try
            {
                dal.UpdateReceive(info);
            }
            catch
            {
                throw;
            }
        }

        public string UpdateOffer(M_ICM_Bidder info, string receipt_no, string amount)
        {
            try
            {
                Nullable<double> namount = common.ConvertNullDouble(amount);
                return dal.UpdateOffer(info, receipt_no, namount);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(string seq)
        {
            try
            {
                int nseq = Convert.ToInt32(seq);
                dal.Delete(nseq);
            }
            catch
            {
                throw;
            }
        }

        public string AmountBidder(string BidId)
        {
            return dal.AmountBidder(BidId);
        }
    }
}
